<template>
  <div id="main" style="height: 400px; width: 600px;"></div>
</template>

<script setup lang="ts">
import * as echarts from 'echarts';
import { onMounted, onUnmounted, ref } from 'vue';

const chartInstance = ref<echarts.ECharts | null>(null);

onMounted(() => {
  const element = document.getElementById('main');
  if (element) {
    chartInstance.value = echarts.init(element);
    chartInstance.value.setOption({
      xAxis: {
        type: 'category',
        data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
      },
      yAxis: {
        type: 'value'
      },
      series: [
        {
          data: [150, 230, 224, 218, 135, 147, 260],
          type: 'line'
        }
      ]
    });
  }
});

onUnmounted(() => {
  if (chartInstance.value) {
    chartInstance.value.dispose(); // 清理 ECharts 实例
  }
});
</script>

<style scoped>
#main {
  height: 400px;
  width: 600px;
}
</style>
